package com.theydream.ichingwisdom.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

import com.theydream.ichingwisdom.R;
import com.theydream.ichingwisdom.tab.TabHostProvider;
import com.theydream.ichingwisdom.tab.TabView;
import com.theydream.ichingwisdom.tab.TabbarView;

public class Divination extends Activity {
	private TabHostProvider tabProvider;
	private TabView tabView;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tabProvider = new TabbarView(this);
		tabView = tabProvider.getTabHost("main");
		tabView.setCurrentView(R.layout.divination);
		View view = tabView.render(4);

		setContentView(view);
		Button email = (Button) findViewById(R.id.email);
		email.setOnClickListener(new OnClickListener() {
			public void onClick(View view) {
				Intent emailIntent = new Intent(
						android.content.Intent.ACTION_SEND);
				emailIntent.setType("text/html");
				emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
						"Enquiry");
				emailIntent.putExtra(
						android.content.Intent.EXTRA_TEXT,
						Html.fromHtml("<b>I would like to make a contact with you.</b>"));
				startActivity(Intent.createChooser(emailIntent,
						"Email to Friend"));

			}
		});
		
		ImageView random1 = (ImageView) findViewById(R.id.random1);
		random1.setOnClickListener(new OnClickListener(){
			public void onClick(View view){
				Intent toRandom1 = new Intent();
				toRandom1.setClass(Divination.this, DivinationResult.class);
				Bundle bundle = new Bundle();
				bundle.putInt("randomNumber", randomCard()); 
				toRandom1.putExtras(bundle); 
				startActivity(toRandom1);
	          }
		});
		
		ImageView random2 = (ImageView) findViewById(R.id.random2);
		random2.setOnClickListener(new OnClickListener(){
			public void onClick(View view){
				Intent toRandom1 = new Intent();
				toRandom1.setClass(Divination.this, DivinationResult2.class);
				Bundle bundle = new Bundle();
				int num1 = randomCard();
				int num2 = randomCard();
				while(num1==num2){
					num2 = randomCard();
				}
				bundle.putInt("randomNumber", num1); 
				bundle.putInt("randomNumber2", num2); 
				toRandom1.putExtras(bundle); 
				startActivity(toRandom1);
	          }
		});
		
		ImageView random3 = (ImageView) findViewById(R.id.random3);
		random3.setOnClickListener(new OnClickListener(){
			public void onClick(View view){
				Intent toRandom1 = new Intent();
				toRandom1.setClass(Divination.this, DivinationResult3.class);
				Bundle bundle = new Bundle();
				int num1 = randomCard();
				int num2 = randomCard();
				int num3 = randomCard();
				while(num1==num2||num2==num3||num1==num3){
					num2 = randomCard();
					num3 = randomCard();
				}
				bundle.putInt("randomNumber", num1); 
				bundle.putInt("randomNumber2", num2); 
				bundle.putInt("randomNumber3", num3); 

				toRandom1.putExtras(bundle); 
				startActivity(toRandom1);
	          }
		});

}

	public void onResume() {
		super.onResume();
	}

	public int randomCard() {
		return (int) ((Math.random() * 64) + 1);
	}

}
